package cuiyt.juc.unsafe.collection;

import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

/**
 * @author cyt
 * @create 2020-09-01 8:54
 */
public class Test {
    static Entity entity = new Entity();
    static Lock lock = new ReentrantLock();

    public static void main(String[] args) throws InterruptedException {

        for (int i = 0; i < 2; i++) {
            new Thread(() -> {
                add();
            }, "" + i).start();
        }

        TimeUnit.SECONDS.sleep(5);
        System.out.println(entity.value);
    }




    /**
     *
     */
    public static void add() {
        for (int i = 0; i < 10000; i++) {
            synchronized (Test.entity){
                entity.value++;
            }
        }
    }
}

class Entity {
    public int value = 0;
}
